<template>
	<div class="order">
		<div class="order-tt">{{tit}}</div>
		<div class="order-lt" v-if="storeNull">
			<ul>
				<li v-for="item in exceptionStoreList">
					<router-link :to="{name: 'aging', query: {storeName: item.storeName, storeCode: item.storeCode, date: dateYear}}">
						<p class="itrate">
							<span>{{item.percentage}}</span>
							<i></i>
						</p>
						<p>{{item.storeName}} <b>({{item.storeCode}})</b></p>
					</router-link>
				</li>
			</ul>
		</div>
		<!-- 无数据时 -->
        <div class="nofind" v-else>
          <div class="nofind_pic">
            <img src="../assets/images/no_findgoods.png" >
          </div>
          <p>当前无异常门店</p>
        </div>
		<!-- 没有展示更多数据 -->
		<div class="order-nw" v-show="flag"><p>没有更多了，亲</p></div>
	</div>
</template>

<style lang="less">
	@import "../less/order/order.main.less";
</style>

<script type="text/ecmascirpt-6">
	import fecha from 'fecha'
	import Cookie from 'js-cookie'
	import ORDER from '@/services/order'
	export default {
		name: 'unusual_store',	
		data () {
			return {
				// 是否显示文本没有更多
				flag: false,
				// 是否数据为空
				storeNull: true,
				// 标题
				tit: '',
				// 异常门店列表
				exceptionStoreList: []
			}
		},
		created () {
		    // 桥接设置标题 及时展示
		 	bridge.setTitle('履约异常门店')
		},
		mounted(){
			// 返回到异常门店时清除超时订单带过来的信息
			Cookie.remove('storeCode')
			//异常门店 判断来源于工作台还是履约首页
			let dataType, rangType
			if (typeof this.$route.query.params !== 'undefined') {
				let params = String(this.$route.query.params).split(',')
				dataType = params[0]
				rangType = params[1]
				const dayValue = 1000 * 60 * 60 * 24
		      	const today = new Date().valueOf()
		      	switch (params[2]) {
		          case 'TODAY':
		            this.dateYear = `${fecha.format(today, 'YYYY-MM-DD')}`
		            break;
		          case 'YESTERDAY':
		            this.dateYear = `${fecha.format(today - dayValue, 'YYYY-MM-DD')}`
		            break;
		          default:
		            this.dateYear = `${fecha.format(today, 'YYYY-MM-DD')}`
		        }
			} else {
				dataType = this.$route.query.dataType
				rangType = this.$route.query.rangType
				this.dateYear = this.$route.query.date
				// 从履约首页进入异常门店 存储来源页的基础数据
				Cookie.set('date', this.$route.query.date)
				Cookie.set('typeCode', this.$route.query.typeCode)
				Cookie.set('areaCode', this.$route.query.areaCode)
				Cookie.set('areaName', this.$route.query.areaName)
			}
			// 请求前加载动画
			CommonUtil.indicator.open()
			// 桥接cookies方法
			bridge.getCookies((cookies) => {
		        let token = cookies.dz_auth_token
		        let body = {
		          typeCode: this.$route.query.typeCode || cookies.dz_area_type,
		          areaCode: this.$route.query.areaCode || cookies.dz_area_code,
		          dataType: dataType,
		          rangType: rangType,
		          date: this.dateYear
		        }
		        console.log(body)
				ORDER.ustore(token, body).then(({data})=>{
					// 请求完关闭动画
					CommonUtil.indicator.close()
					console.log(data)
					// 成功之后操作
					if (data.errorCode === 0) {
						this.tit = data.body.hintInfo
						if (typeof data.body.exceptionStoreList !== 'undefined' && data.body.exceptionStoreList.length) {
							this.storeNull = true 
							this.flag = true
							this.exceptionStoreList = data.body.exceptionStoreList
						} else {
							this.storeNull = false
							this.flag = false
						}
					} else {
						CommonUtil.toast(data.errorDesc || CommonUtil.interfaceTip)
					}
				})
			})
		},
		computed: {			

		},
		methods: {

		}
	}
</script>